﻿using System;
using System.Collections.Generic;
using StructureMap.Configuration.DSL;
using Microsoft.Practices.ServiceLocation;

namespace NMA.Infrastructure.NHibernate.Bootstrapper
{
    using NMA.Infrastructure.Configuration;    

    /// <summary>
    /// http://www.codeproject.com/Articles/51640/Common-Service-Locator-Separate-hard-reference-of-.aspx
    /// </summary>
    public abstract class CommonBootStrapper
    {
        public static IServiceLocator Locator;

        protected IConfigurationManager _configurationManager;
        protected IList<Type> _registries;

        protected CommonBootStrapper(IList<Type> registries, IConfigurationManager configurationManager, string conStringName, params string[] bootTaskAssemblies)
        {
            _registries = registries;
            _configurationManager = configurationManager;
            Locator = CreateServiceLocator(conStringName, bootTaskAssemblies);
            Run();
        }

        /// <summary>
        /// Create Service Locator object, including create and configure Nhibernate object
        /// </summary>
        /// <returns>Service Locator instance</returns>
        protected abstract IServiceLocator CreateServiceLocator(string conStringName, params string[] bootTaskAssemblies);

        /// <summary>
        /// Run all task in background
        /// </summary>
        protected abstract void Run();
    }
}
